
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbFlowCompanyMiddleDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlowCompanyMiddle tbFlowCompanyMiddle=null;
    private List<TbFlowCompanyMiddle> tbFlowCompanyMiddleList=null;

    public boolean add(TbFlowCompanyMiddle inTbFlowCompanyMiddle){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_FlowCompanyMiddle(CompanyId,FlowId,UserId) values(?,?,?)";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowCompanyMiddle.getCompanyId());
        pt.setInt(2,inTbFlowCompanyMiddle.getFlowId());
        pt.setInt(3,inTbFlowCompanyMiddle.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowCompanyMiddleId){
        return UtilDAO.del("Tb_FlowCompanyMiddle", "FlowCompanyMiddleId", inFlowCompanyMiddleId);
    }
    public boolean edit(TbFlowCompanyMiddle inTbFlowCompanyMiddle){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_FlowCompanyMiddle set CompanyId=?,FlowId=?,UserId=?,CreateTime=getdate() where FlowCompanyMiddleId=?";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowCompanyMiddle.getCompanyId());
        pt.setInt(2,inTbFlowCompanyMiddle.getFlowId());
        pt.setInt(3,inTbFlowCompanyMiddle.getUserId());
        pt.setInt(4,inTbFlowCompanyMiddle.getFlowCompanyMiddleId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlowCompanyMiddle getTbFlowCompanyMiddleByFlowCompanyMiddleId(int inFlowCompanyMiddleId) {
        tbFlowCompanyMiddle=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowCompanyMiddle where FlowCompanyMiddleId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowCompanyMiddleId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlowCompanyMiddle == null)tbFlowCompanyMiddle = getTbFlowCompanyMiddle(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowCompanyMiddle;
    }
    public List<TbFlowCompanyMiddle> getTbFlowCompanyMiddleAll() {
        tbFlowCompanyMiddleList=new ArrayList<TbFlowCompanyMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowCompanyMiddle";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowCompanyMiddleList.add(getTbFlowCompanyMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowCompanyMiddleList;
    }
    public List<TbFlowCompanyMiddle> getTbFlowCompanyMiddleAll(VskPage vp) {
        tbFlowCompanyMiddleList=new ArrayList<TbFlowCompanyMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowCompanyMiddle";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_FlowCompanyMiddle", "FlowCompanyMiddleId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowCompanyMiddleList.add(getTbFlowCompanyMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowCompanyMiddleList;
    }
    public TbFlowCompanyMiddle getTbFlowCompanyMiddle(ResultSet rs) throws Exception{
        TbFlowCompanyMiddle tbFlowCompanyMiddle = new TbFlowCompanyMiddle();
        tbFlowCompanyMiddle.setFlowCompanyMiddleId(rs.getInt("FlowCompanyMiddleId"));
        tbFlowCompanyMiddle.setCompanyId(rs.getInt("CompanyId"));
        tbFlowCompanyMiddle.setFlowId(rs.getInt("FlowId"));
        tbFlowCompanyMiddle.setUserId(rs.getInt("UserId"));
        tbFlowCompanyMiddle.setCreateTime(rs.getString("CreateTime"));
        return tbFlowCompanyMiddle;
    }
}
